<template>
	<view>
		<view class="headcontent">
			<view class="contentbox" :style="'height:'+headHeight+'rpx;'">
				<image src="../../../static/images/cc/left.png" mode="widthFix" @click="goBack"></image>
			</view>
		</view>
		<view class="banner">
			<swiper :indicator-dots="false" :autoplay="true" :circular="true" :interval="3000" :duration="1000"
				indicator-active-color="#84BD00" indicator-color="rgba(66, 137, 243, 0.2)">
				<swiper-item v-for="(item, index) in arr_shop_image" :key="index">
					<view class="swiper-item">
						<image :src="tu(item)" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
			<view class="shadow"></view>
			<view class="dropBox">
				<view class="drop select"></view>
				<view class="drop"></view>
			</view>
		</view>
		<view class="shop">
			<view class="shopAbox">
				<view class="shopCon">
					<image :src="tu(con.avatar)" mode="widthFix"></image>
					<view class="shopDetail">
						<view class="shopName">{{con.shopname}}</view>
						<view class="shopNum"><text>{{con.follow}}</text> 关注</view>
					</view>
				</view>
				<view class="follow" @tap='guanzhu()' :class="'yiguanzhu'+con.is_follow">{{con.is_follow == 0 ? '+关注' : '已关注'}}</view>
			</view>
			<view class="shopBbox">
				<view class="shopLcon">
					<view class="divide">{{Number.isInteger(con.score) ? con.score + '.0' : con.score}}</view>
					<view class="star">
						<image src="../../../static/images/cc/star1.png" mode="widthFix" v-for="(item,index) in Math.floor(con.score)" :key="index"></image>
						<image src="../../../static/images/cc/star3.png" mode="widthFix" v-for="(item,index) in Number.isInteger(con.score) ? 0: 1" :key="index"></image>
						<image src="../../../static/images/cc/star2.png" mode="widthFix" v-for="(item,index) in 5 - Math.ceil(con.score)" :key="index"></image>
					</view>
				</view>
				<view class="label">
					<view>月销{{con.monthly_sales_order}}</view>
					<view>人均￥{{con.per_capita}}</view>
				</view>
			</view>
			<view class="shopCbox">
				<view class="addressCon">
					<view class="address">{{con.address}}</view>
					<view class="km">距您{{junin(con.fromyou)}}</view>
				</view>
				<view class="operate">
					<view class="use">
						<image @tap='daohang' src="../../../static/images/cc/gps.png" mode="widthFix"></image>
						<view>导航</view>
					</view>
					<view class="use">
						<!-- <button type="primary" @click="dianhua">拨打电话</button> -->
						<image @tap='dianhua' src="../../../static/images/cc/tel.png" mode="widthFix"></image>
						<view>电话</view>
					</view>
				</view>
			</view>
		</view>
		<view class="title">
			<view class="line"></view>
			<view class="titleName">全部套餐</view>
		</view>
		<block v-for="(item,index) in con.goods" :key='index'>
			<view class="list">
				<image :src="tu(item.image)" mode="aspectFill"></image>
				<view class="goods">
					<view class="goodsName">{{item.title}}</view>
					<view class="goodsLave">{{item.description}}</view>
					<view class="evaluate">
						<image src="../../../static/images/cc/okk.png" mode="widthFix"></image>
						<view>100%好评</view>
					</view>
					<view class="money">
						<view class="price"><text>￥</text>{{item.price}}</view>
						<view class="original">￥{{item.old_price}}</view>
					</view>
					<view @tap='tiaozhuan(item.id)' class="buy">抢购</view>
				</view>
			</view>
			<!-- 广告占位符 -->
			<!-- <image v-if='(index+1) % 5 === 0' src="../../../static/images/cc/gg.png" mode="widthFix" class="advertisement"></image> -->
		</block>
	</view>
</template>

<script>
	import wanlshop_config from '@/common/config/config.js';
	let cdnurl = wanlshop_config.cdnurl, appurl = wanlshop_config.appurl, header
	export default {
		data() {
			return {
				con: {},
				headHeight: 0,
				yiguanzhu: 0,
				arr_shop_image: []
			};
		},
		methods:{
			goBack(){
				uni.navigateBack()
			},
			tu(e){
				if(e){
					if(e.indexOf('http') == -1){
						return `${cdnurl}${e}`	
					}else{
						return e;
					}
				}else{
					return ''
				}
			},
			junin(e){
				if(e){
					let shu = Math.round((e/1000 + Number.EPSILON) * 100) / 100;
					return `${shu}公里`
				}else{
					return ''
				}
			},
			dianhua(){
				uni.makePhoneCall({
					phoneNumber: String(this.con.mobile)
				});
			},
			daohang(){
				uni.openLocation({
					latitude: Number(this.con.latitude), // 目标纬度
					longitude: Number(this.con.longitude), // 目标经度
					name: this.con.shopname, // 目标地点名称
					address: this.con.address, // 目标地点详细地址
					success: () => {
					  console.log('导航成功');
					},
					fail: (err) => {
					  console.error('导航失败', err);
					}
				  });
			},
			tiaozhuan(e){
				uni.navigateTo({
					url: `/pages/dispatch/groupBuying/groupBuying?id=${e}`
				});
			},
			guanzhu(){
				uni.showLoading({
					title: 'loading...'
				})
				uni.request({
					url: `${appurl}/wanlshop/mchomepage/toFreight`,
					data:{
						id: this.con.id,
						type: this.con.is_follow
					},
					header,
					complete: res => {
						this.con.is_follow = 1-this.con.is_follow
						uni.hideLoading()
					}
				});
			}
		},
		onLoad(e){
			let lng, lat, id
			if('undefined' == typeof(e.id)){
				//这块生产环境要删
				id = 15
			}else{
				id = e.id
			}
			header = {token: this.$store.state.user.token}
			uni.getLocation({
			  type: 'gcj02', // 使用国测局坐标系
			  isHighAccuracy: true, // 开启高精度定位
			  success: (res) => {
				uni.request({
					url: `${appurl}/wanlshop/mchomepage/getMchomePage`,
					data:{
						id,
						lng: res.longitude,
						lat: res.latitude
					},
					header,
					complete: res => {
						if(res.res.code === 1){
							this.con = res.data
							console.log(this.con)
							if(this.con.shop_image){
								let b = this.con.shop_image.split(','), c = [], i
								for(i in b){
									c.push(b[i])
								}
								this.arr_shop_image = c
							}
						}else{
							uni.showToast({
							    title: '服务器繁忙',
							    icon: 'none'
							});
						}
					}
				});
			  },
			  fail: (err) => {
			    console.error('获取位置失败：', err);
			  }
			});
			
		},
		created() {
			this.headHeight = (uni.getSystemInfoSync().statusBarHeight + 45) * 2
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.headcontent {
		width: 750rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		top: 0;
		z-index: 6666;

		.contentbox {
			width: 750rpx;
			display: flex;
			position: relative;
			align-items: center;

			image {
				width: 50rpx;
				height: 50rpx;
				margin-left: 20rpx;
				position: relative;
				z-index: 999;
			}
		}
	}

	.banner {
		width: 750rpx;
		height: 498rpx;
		position: relative;

		.shadow {
			width: 750rpx;
			height: 498rpx;
			position: absolute;
			top: 0;
			z-index: 1;
			background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 40%);
		}

		swiper {
			width: 750rpx;
			height: 498rpx;
			position: relative;



			.swiper-item {
				width: 750rpx;
				height: 498rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.dropBox {
			width: 700rpx;
			margin-left: 34rpx;
			display: flex;
			position: absolute;
			bottom: 60rpx;

			.drop {
				width: 46rpx;
				height: 7rpx;
				background: rgba(255, 255, 255, 0.3);
				border-radius: 50rpx;
				margin-right: 8rpx;
			}

			.select {
				background-color: #fff;
			}
		}
	}

	.shop {
		width: 750rpx;
		margin-top: -45rpx;
		position: relative;
		background-color: #F7F7F7;
		border-radius: 40rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		padding-top: 45rpx;

		.shopAbox {
			width: 664rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.shopCon {
				display: flex;
				align-items: center;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}

				.shopDetail {
					margin-left: 32rpx;

					.shopName {
						font-size: 33rpx;
						color: #3D3D3D;
					}

					.shopNum {
						font-size: 26rpx;
						color: #999999;
						margin-top: 10rpx;

						text {
							color: #FB4E2F;
							margin-right: 10rpx;
						}
					}
				}
			}

			.follow {
				width: 157rpx;
				height: 65rpx;
				border: 1px solid #FB4E2F;
				color: #FB4E2F;
				font-size: 30rpx;
				border-radius: 10rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.yiguanzhu1{
				color: #999999;
				background: #e6e6e6;
				border: #787878 1px solid;
			}
		}

		.shopBbox {
			width: 664rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 33rpx;

			.shopLcon {
				width: 200rpx;
				height: 32rpx;
				background: rgba(251, 78, 47, 0.08);
				border-radius: 50rpx;
				display: flex;

				.divide {
					width: 72rpx;
					height: 32rpx;
					background-color: #FB4E2F;
					border-radius: 50rpx 0px 8rpx 50rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: #fff;
				}

				.star {
					width: 138rpx;
					height: 32rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 16rpx;
						height: 16rpx;
						margin-left: 4rpx;
						margin-right: 4rpx;
					}
				}
			}

			.label {
				display: flex;
				align-items: center;

				view {
					font-size: 26rpx;
					color: #999999;
					margin-left: 38rpx;
				}
			}
		}

		.shopCbox {
			width: 664rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 40rpx;

			.addressCon {
				width: 470rpx;

				.address {
					font-size: 30rpx;
					color: #3D3D3D;
				}

				.km {
					font-size: 26rpx;
					color: #999999;
					margin-top: 10rpx;
				}
			}

			.operate {
				display: flex;

				.use {
					width: 52rpx;
					margin-left: 42rpx;
					display: flex;
					flex-wrap: wrap;
					justify-content: center;

					image {
						width: 52rpx;
						height: 52rpx;
					}

					view {
						font-size: 26rpx;
						color: #999999;
					}
				}
			}
		}
	}

	.title {
		width: 664rpx;
		margin-left: 43rpx;
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		margin-bottom: 30rpx;

		.line {
			width: 8rpx;
			height: 34rpx;
			background-color: #FB4E2F;
			border-radius: 50rpx;
		}

		.titleName {
			font-size: 33rpx;
			color: #3D3D3D;
			margin-left: 17rpx;
		}
	}

	.list {
		width: 690rpx;
		background-color: #fff;
		padding: 28rpx 0;
		margin-left: 30rpx;
		border-radius: 20rpx;
		display: flex;
		margin-bottom: 20rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			border-radius: 10rpx;
			margin-left: 26rpx;
		}

		.goods {
			width: 416rpx;
			margin-left: 22rpx;
			display: flex;
			align-content: space-between;
			flex-wrap: wrap;
			position: relative;

			.goodsName {
				width: 100%;
				font-size: 30rpx;
				color: #3D3D3D;
			}

			.goodsLave {
				width: 100%;
				font-size: 26rpx;
				color: #999999;
			}

			.evaluate {
				width: 157rpx;
				height: 39rpx;
				border-radius: 50rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: #F7F7F7;

				image {
					width: 20rpx;
					height: 20rpx;
					margin-left: 0 !important;
				}

				view {
					font-size: 22rpx;
					color: #666666;
					margin-left: 6rpx;
				}
			}

			.money {
				width: 100%;
				display: flex;
				align-items: flex-end;

				.price {
					color: #FB4E2F;
					font-size: 36rpx;

					text {
						font-size: 26rpx;
					}
				}

				.original {
					font-size: 26rpx;
					color: #999999;
					margin-left: 10rpx;
					text-decoration: line-through;
					margin-bottom: 4rpx;
				}
			}

			.buy {
				position: absolute;
				bottom: 0;
				right: 0;
				width: 136rpx;
				height: 65rpx;
				background-color: #FB4E2F;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 50rpx;
				font-size: 26rpx;
				color: #fff;
			}
		}
	}

	.advertisement {
		width: 690rpx;
		margin-left: 30rpx;
		margin-bottom: 20rpx;
	}
</style>